package com.shwread.android.qysw.activity;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView;

import com.google.gson.reflect.TypeToken;
import com.shwread.android.qysw10000152.R;
import com.shwread.android.ui.customview.NoScrollGridView;
import com.shwread.android.ui.dialog.CommonDialog;
import com.shwread.android.ui.dialog.SimpleListener;
import com.shwread.android.ui.page.chat.MomentsPage;
import com.shwread.android.ui.widget.CircleImageView;
import com.shwread.android.ui.widget.CommentView;
import com.shwread.android.ui.widget.refresh.PullToRefreshScrollView;
import com.shwread.android.ui.widget.refresh.PullToRefreshUtil;
import com.shwread.android.ui.widget.refresh.base.PullToRefreshBase;
import com.shwread.android.ui.widget.refresh.base.PullToRefreshBase.OnRefreshListener;
import com.shwread.http.ActionHelp;
import com.shwread.http.base.ObjectHttpResponseHandler;
import com.shwread.http.base.TextHttpResponseHandler;
import com.shwread.http.util.Logger;

import org.apache.http.Header;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;

import logic.bean.CommentBean;
import logic.bean.LoginInfo;
import logic.bean.MeCommentBean;
import logic.bean.NewInteractionInfo;
import logic.bean.NumberInfo;
import logic.constants.Const;
import logic.constants.DefaultConsts;
import logic.util.DateUtil;
import logic.util.ImageLoaderUtil;
import logic.util.Util;
import logic.util.Utils;


/**
 * @author :yqq
 * @version 创建时间：2015-5-7 下午4:14:06 互动详情界面
 */
public class NewInteractionDetailsActivity
        extends
        BaseBusinessActivity
        implements
        OnClickListener
{
	
	private Context                 context;
	private BaseBusinessActivity    bActivity;
	
	private TextView                tvTitle;
	private Button                  backbtn;
	private ListView                details_lv;
	private PullToRefreshScrollView psView;                                     // 内容视图
	private LinearLayout            llayEmpty;
	
	/********* 资讯信息 *************/
	
	private NewInteractionInfo      interactionInfo;
	private String[]                images;                                     //图片地址数组，用于显示首张图片
	private CircleImageView ivHead;
	private TextView                tvName;
	private TextView                tvTime;
	private RelativeLayout          ivImage_ll;
	private ImageView               ivImage;
	private ImageView               ivmanager_label;
	private TextView                tvIntro;
	private String                  targetType, targetValue;                    //新版互动中心  targetType=“6”  targetValue 为主题ID
	private MeCommentBean           meCommentBean;
	/************ 评论框 **************/
	private LinearLayout            llayAddComment;
	private CommentView             addCommentView;
	
	/************** 分页信息 ****************/
	private int                     pageLength   = 30;                          // 页面数据长度
	private long                    lastItemTime = 0L;                          // 当前页最后一条数据的创建时间
	                                                                             
	private MyAdapter               adapter;
	private boolean                 isShowInput  = false;                       // 是否显示输入法
	private int                     getDataFlag  = 0;                           // 获取数据的方式 0 为首次进入 1为刷新 2为加载更多
	                                                                             
	private TextView                tvCommentCount;
	
	private List<CommentBean>       commentList  = new ArrayList<CommentBean>();
	
	private LoginInfo               info         = new LoginInfo();
	private boolean                 isHasMore    = true;
	private NoScrollGridView        gridView;
	private ArrayList<String>       list;
	private GridViewAdapter         gvAdapter;
	private String                  hasDelete    = "";
	private TextView                tvDelete;
	private ImageView               imAtlas;
	private int                     width;
	private int                     height;
	private long                    topicId;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.new_interaction_details_layout);
		getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
		context = this;
		bActivity = this;
		
		Bundle bundle = getIntent().getExtras();
		if (bundle != null && bundle.containsKey("NewInteractionInfo"))
		{
			interactionInfo = (NewInteractionInfo) bundle.getSerializable("NewInteractionInfo");
			hasDelete = bundle.getString("delete");
			width = bundle.getInt("width", -1);
			height = bundle.getInt("height", -1);
			topicId = interactionInfo.getId();
		}
		else if (bundle != null && bundle.containsKey("MeCommentBean"))
		{
			meCommentBean = (MeCommentBean) bundle.getSerializable("MeCommentBean");
			hasDelete = meCommentBean.getAuthorId();
			topicId = meCommentBean.getTopicId();
		}
		else
		{
			return;
		}
		findView();
		initData();
		addListener();
		addData();
	}
	
	private void addData() {
		lastItemTime = 0L;
		this.getDataFlag = 0;
		getCommentList();
		getCommentTotalNum();
	}
	
	private Handler handler = new Handler()
	                        {
		                        @Override
		                        public void handleMessage(Message msg) {
			                        switch (msg.what) {
										case DefaultConsts.COMMENT_SUBMIT_SUCCESS:
											//评论成功
											refrush();
											break;
										
										default:
											break;
									}
								}
	                        };
	
	/*
	 * (non-Javadoc)
	 * @see
	 * com.shwread.android.qysw.activity.BaseBusinessActivity#getUIHandler()
	 */
	@Override
	public Handler getUIHandler() {
		// TODO Auto-generated method stub
		return handler;
	}
	
	@Override
	protected void onResume() {
		super.onResume();
		//		lastItemTime=0L;
		//		this.getDataFlag = 0;
		//		getCommentList();
		//		getCommentTotalNum();
		
	}
	
	@Override
	public void onClick(View view) {
		switch (view.getId()) {
			case R.id.common_header_back:
				finish();
				break;
			case R.id.new_im_bigimage:
				gotoImangeDetailActivity();
				break;
			default:
				break;
		}
	}
	
	private void findView() {
		tvTitle = (TextView) findViewById(R.id.common_header_name);
		backbtn = (Button) findViewById(R.id.common_header_back);
		tvTitle.setText("互动详情");
		backbtn.setVisibility(View.VISIBLE);
		
		// 资讯视图
		View headview = LayoutInflater.from(context).inflate(R.layout.new_interaction_singleinfo_item, null);
		// View headview = findViewById(R.id.new_interation_details_head_view);
		gridView = (NoScrollGridView) headview.findViewById(R.id.gridview);
		tvDelete = (TextView) headview.findViewById(R.id.tv_delete);
		if (hasDelete.equals(Const.UserStaffId))
		{
			tvDelete.setVisibility(View.VISIBLE);
		}
		ivHead = (CircleImageView) headview.findViewById(R.id.new_im_headportrait);
		tvName = (TextView) headview.findViewById(R.id.new_tv_info_title);
		tvTime = (TextView) headview.findViewById(R.id.new_tv_publishtime);
		tvIntro = (TextView) headview.findViewById(R.id.new_tv_info_from);
		ivImage_ll = (RelativeLayout) headview.findViewById(R.id.new_im_bigimage_ll);
		ivImage = (ImageView) headview.findViewById(R.id.new_im_bigimage);
		imAtlas = (ImageView) headview.findViewById(R.id.new_im_atlas);
		View headView2 = LayoutInflater.from(context).inflate(R.layout.new_interaction_details_list_view_head_two, null);
		
		tvCommentCount = (TextView) headView2.findViewById(R.id.new_interaction_detail_head_two_count_tv);
		// 评论列表
		
		ivmanager_label = (ImageView) headview.findViewById(R.id.new_im_manager_label);//经理标注
		
		//评论列表
		
		psView = (PullToRefreshScrollView) findViewById(R.id.new_interaction_details_content_view_psv);
		details_lv = (ListView) findViewById(R.id.new_interaction_details_listview);
		llayEmpty = (LinearLayout) findViewById(R.id.new_i_detail_comment_empty_llay);
		details_lv.addHeaderView(headview);
		details_lv.addHeaderView(headView2);
		// 评论输入框
		llayAddComment = (LinearLayout) findViewById(R.id.new_interaction_add_llay);
		addCommentView = new CommentView(this);
		llayAddComment.addView(addCommentView);
		
	}
	
	private void addListener() {
		backbtn.setOnClickListener(this);
		addCommentView.setCommentParams(bActivity, targetType, targetValue);
		
		ivImage.setOnClickListener(this);
		
		psView.setOnRefreshListener(new OnRefreshListener<ScrollView>() {

			@Override public void onRefresh(PullToRefreshBase<ScrollView> refreshView) {
				if (psView.isHeaderShown()) {
					refrush();
				} else if (psView.isFooterShown()) {
					loadMore();
				}
			}
		});
		
		details_lv.setOnItemClickListener(new OnItemClickListener() {

			@Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
				if (position > details_lv.getHeaderViewsCount() - 1) {

					CommentBean info =
							(CommentBean) commentList.get(position - details_lv.getHeaderViewsCount());

					if (isShowInput) {
						addCommentView.setDefaultHint();
						addCommentView.setCommentParams(bActivity, targetType, targetValue);
						addCommentView.hideInputMethod();
						return;
					}

					if (Const.phone_number.equals(info.getCommentUserAccount())) {
						addCommentView.setDefaultHint();
						addCommentView.setCommentParams(bActivity, targetType, targetValue);
					} else {
						addCommentView.setHintString(info.commentUserNickName);
						addCommentView.setReplyParams(bActivity, targetType, targetValue, info.commentUserId,
								info.commentUserAccount, info.commentId);
					}
					addCommentView.showInputMethod();
				}
			}
		});
		
		tvDelete.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v) {
				CommonDialog dialog = new CommonDialog(context, new SimpleListener()
				{
					
					@Override
					public void ok() {
						ActionHelp.deleteTopic(context, topicId, new MyDeleteHandler());
					}
				})
				{
				};
				dialog.show();
			}
		});
	}
	
	/**
	 * 初始化数据
	 */
	private void initData() {
		if (interactionInfo != null && Utils.isNotEmpty(interactionInfo.getImageList()))
		{
			String[] strArray = null;
			strArray = interactionInfo.getImageList().split(",");
			list = new ArrayList<String>();
			for (String url : strArray)
			{
				list.add(url);
			}
			gridView.setSelector(new ColorDrawable(Color.TRANSPARENT));
			
			if (MomentsPage.width == 480) gridView.setVerticalSpacing(3);
			if (list.size() == 4)
			{
				gridView.setNumColumns(2);
				gridView.setPadding(0, 0, (MomentsPage.width * 3 / 4 - 10) / 3 + 5, 0);
				
			}
			gvAdapter = new GridViewAdapter(list);
			gridView.setAdapter(gvAdapter);
			if (list.size() == 1)
			{
				gridView.setVisibility(View.GONE);
				if (width != -1 && height != -1) imAtlas.setLayoutParams(new LayoutParams(width, height));
				else
				{
					imAtlas.setLayoutParams(new LayoutParams(300, 500));
					
				}
				imAtlas.setVisibility(View.VISIBLE);
				ImageLoaderUtil.loadWebUrl(list.get(0), imAtlas);
				
			}
			imAtlas.setOnClickListener(new OnClickListener()
			{
				
				@Override
				public void onClick(View v) {
					Intent atlasSeeIntent = new Intent();
					atlasSeeIntent.setClass(context, NewInteractionAtlasSeeActivity.class);
					atlasSeeIntent.putExtra(DefaultConsts.NI_ATLASSEE_URL, list);
					atlasSeeIntent.putExtra(DefaultConsts.FROM_TYPE, DefaultConsts.NI_FROM_WEBURL);
					atlasSeeIntent.putExtra(DefaultConsts.NI_POSITION, 0);
					context.startActivity(atlasSeeIntent);
				}
			});
			gridView.setOnItemClickListener(new OnItemClickListener()
			{
				
				@Override
				public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
					Intent atlasSeeIntent = new Intent();
					atlasSeeIntent.setClass(context, NewInteractionAtlasSeeActivity.class);
					atlasSeeIntent.putExtra(DefaultConsts.NI_ATLASSEE_URL, list);
					atlasSeeIntent.putExtra(DefaultConsts.FROM_TYPE, DefaultConsts.NI_FROM_WEBURL);
					atlasSeeIntent.putExtra(DefaultConsts.NI_POSITION, position);
					
					startActivity(atlasSeeIntent);
					
				}
			});
		}
		else if (meCommentBean != null && Utils.isNotEmpty(meCommentBean.getTopicImgList()))
		{
			String[] strArray = null;
			strArray = meCommentBean.getTopicImgList().split(",");
			list = new ArrayList<String>();
			for (String url : strArray)
			{
				list.add(url);
			}
			gridView.setSelector(new ColorDrawable(Color.TRANSPARENT));
			gvAdapter = new GridViewAdapter(list);
			gridView.setAdapter(gvAdapter);
			gridView.setOnItemClickListener(new OnItemClickListener()
			{
				
				@Override
				public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
					Intent atlasSeeIntent = new Intent();
					atlasSeeIntent.setClass(context, NewInteractionAtlasSeeActivity.class);
					atlasSeeIntent.putExtra(DefaultConsts.NI_ATLASSEE_URL, list);
					atlasSeeIntent.putExtra(DefaultConsts.FROM_TYPE, DefaultConsts.NI_FROM_WEBURL);
					atlasSeeIntent.putExtra(DefaultConsts.NI_POSITION, position);
					
					startActivity(atlasSeeIntent);
					
				}
			});
		}
		adapter = new MyAdapter();
		details_lv.setAdapter(adapter);
		
		if (interactionInfo != null)
		{ //判断是否显示图片图集
			if (Utils.isNotEmpty(interactionInfo.getImageList()))
			{
				images = interactionInfo.getImageList().split(",");
				
				if (images.length > 0)
				{
					if (images.length > 1)
					{
						ivImage_ll.setVisibility(View.VISIBLE);
					}
					ImageLoaderUtil.loadWebUrl(images[0], ivImage);
				}
			}
			else
			{
				ivImage_ll.setVisibility(View.GONE);
			}
			//判断经理标注  及头像是否设置
			if ((interactionInfo.getAutorRole()).equals("3"))
			{//系统
				ivmanager_label.setVisibility(View.GONE);
				ivHead.setImageResource(R.drawable.new_i_recommend_theme);
				tvName.setText("推荐主题");
			}
			else if ((interactionInfo.getAutorRole()).equals("1"))
			{//经理
				ivmanager_label.setVisibility(View.VISIBLE);
				if (Utils.isEmpty(interactionInfo.getAuthorHeaderImage()))
				{
					ivHead.setImageResource(R.drawable.new_i_head_protrait_empty_icon);
				}
				else
				{
					ImageLoaderUtil.loadWebUrl(interactionInfo.getAuthorHeaderImage(), ivHead, ImageLoaderUtil.getOptions(R.drawable.bg_comment_defaulthead));
				}
				tvName.setText(interactionInfo.getAuthorName());
			}
			else
			{//用户
				ivmanager_label.setVisibility(View.GONE);
				if (Utils.isEmpty(interactionInfo.getAuthorHeaderImage()))
				{
					ivHead.setImageResource(R.drawable.new_i_head_protrait_empty_icon);
				}
				else
				{
					//					ImageLoaderUtil.loadWebUrl(interactionInfo.getAuthorHeaderImage(), ivHead);
					ImageLoaderUtil.loadWebUrl(interactionInfo.getAuthorHeaderImage(), ivHead, ImageLoaderUtil.getOptions(R.drawable.bg_comment_defaulthead));
				}
				tvName.setText(interactionInfo.getAuthorName());
			}
			
			//			tvName.setText(interactionInfo.getAuthorName());
			tvTime.setText(DateUtil.getRegionTime(interactionInfo.getPublishTime()));
			tvIntro.setText(interactionInfo.getContent());
			
			targetValue = interactionInfo.getId() + "";
			targetType = "6";
		}
		else if (meCommentBean != null)
		{ //判断是否显示图片图集
			if (Utils.isNotEmpty(meCommentBean.getTopicImgList()))
			{
				images = meCommentBean.getTopicImgList().split(",");
				
				if (images.length > 0)
				{
					if (images.length > 1)
					{
						ivImage_ll.setVisibility(View.VISIBLE);
					}
					ImageLoaderUtil.loadWebUrl(images[0], ivImage);
				}
			}
			else
			{
				ivImage_ll.setVisibility(View.GONE);
			}
			//判断经理标注  及头像是否设置
			if ((meCommentBean.getAuthorRole()).equals("3"))
			{//系统
				ivmanager_label.setVisibility(View.GONE);
				ivHead.setImageResource(R.drawable.new_i_recommend_theme);
				tvName.setText("推荐主题");
			}
			else if ((meCommentBean.getAuthorRole()).equals("1"))
			{//经理
				ivmanager_label.setVisibility(View.VISIBLE);
				if (Utils.isEmpty(meCommentBean.getAuthorHeaderImage()))
				{
					ivHead.setImageResource(R.drawable.new_i_head_protrait_empty_icon);
				}
				else
				{
					ImageLoaderUtil.loadWebUrl(meCommentBean.getAuthorHeaderImage(), ivHead, ImageLoaderUtil.getOptions(R.drawable.bg_comment_defaulthead));
				}
				tvName.setText(meCommentBean.getTopicNickName());
			}
			else
			{//用户
				ivmanager_label.setVisibility(View.GONE);
				if (Utils.isEmpty(meCommentBean.getAuthorHeaderImage()))
				{
					ivHead.setImageResource(R.drawable.new_i_head_protrait_empty_icon);
				}
				else
				{
					//					ImageLoaderUtil.loadWebUrl(interactionInfo.getAuthorHeaderImage(), ivHead);
					ImageLoaderUtil.loadWebUrl(meCommentBean.getAuthorHeaderImage(), ivHead, ImageLoaderUtil.getOptions(R.drawable.bg_comment_defaulthead));
				}
				tvName.setText(meCommentBean.getTopicNickName());
			}
			
			//			tvName.setText(interactionInfo.getAuthorName());
			tvTime.setText(DateUtil.getRegionTime(meCommentBean.getPublishTime()));
			tvIntro.setText(meCommentBean.getContent());
			
			targetValue = meCommentBean.getTopicId() + "";
			targetType = "6";
		}
	}
	
	private class MyDeleteHandler
	        extends
	        TextHttpResponseHandler
	{
		
		@Override
		public void onFailure(int arg0, Header[] arg1, String arg2, Throwable arg3) {
		}
		
		@Override
		public void onSuccess(int arg0, Header[] arg1, String arg2) {
			MomentsPage.instance.contentItemView.getInteractionData(1);
			Util.showToast(context, "删除成功");
			finish();
			
		}
		
	}
	
	/**
	 * 获取评论列表的信息
	 */
	private void getCommentList() {
		ActionHelp.qryCommentList(context, targetType, targetValue, lastItemTime, pageLength, new GetCommentListHandler());
	}
	
	/**
	 * 查询评论总数
	 */
	private void getCommentTotalNum() {
		ActionHelp.qryCommentPraiseNum(context, targetType, targetValue, new GetCommentTotalNumHandler());
	}
	
	/**
	 * 加载更多
	 */
	private void loadMore() {
		if (isHasMore)
		{
			this.getDataFlag = 2;
			lastItemTime = commentList.get(commentList.size() - 1).getCreateTime();
			getCommentList();
			PullToRefreshUtil.initLabel(context, psView);
		}
		else
		{
			PullToRefreshUtil.setLoadLabel(psView, "没有更多了");
			psView.onRefreshComplete();
		}
	}
	
	/**
	 * 刷新页面数据
	 */
	private void refrush() {
		this.getDataFlag = 1;
		lastItemTime = 0L;
		getCommentList();
		getCommentTotalNum();
		PullToRefreshUtil.initLabel(context, psView);
	}
	
	/**
	 * 跳转到图片详情页
	 */
	private void gotoImangeDetailActivity() {
		ArrayList<String> imageList = new ArrayList<String>(); // 图片地址list用于页面传递
		for (int i = 0; i < images.length; i++)
		{
			imageList.add(images[i]);
		}
		
		Intent intent = new Intent(NewInteractionDetailsActivity.this, NewInteractionAtlasSeeActivity.class);
		intent.putExtra(DefaultConsts.FROM_TYPE, DefaultConsts.NI_FROM_WEBURL);
		intent.putExtra(DefaultConsts.NI_ATLASSEE_URL, imageList);
		startActivity(intent);
	}
	
	/** 回到顶部 */
	private void gotoTop() {
		psView.post(new Runnable()
		{
			@Override
			public void run() {
				psView.getRefreshableView().scrollTo(0, 0);
			}
		});
	}
	
	/******************** 监听事件 *******************************/
	private class GetCommentListHandler
	        extends
	        ObjectHttpResponseHandler<List<CommentBean>>
	{
		
		/*
		 * (non-Javadoc)
		 * @see com.shwread.http.base.ObjectHttpResponseHandler#onFailure(int,
		 * org.apache.http.Header[], java.lang.String, java.lang.Throwable)
		 */
		@Override
		public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
			Logger.e(throwable);
			psView.onRefreshComplete();
		}
		
		/*
		 * (non-Javadoc)
		 * @see com.shwread.http.base.ObjectHttpResponseHandler#onSuccess(int,
		 * org.apache.http.Header[], java.lang.Object, java.lang.String)
		 */
		@Override
		public void onSuccess(int statusCode, Header[] headers, List<CommentBean> object, String responseString) {
			Logger.i(responseString);
			psView.onRefreshComplete();
			if (getDataFlag != 2)
			{
				//页面定位到顶部
				gotoTop();
			}
			if (object != null && object.size() > 0)
			{
				//				details_lv.setVisibility(View.VISIBLE);
				llayEmpty.setVisibility(View.GONE);
				if (object.size() < pageLength)
				{
					isHasMore = false;
				}
				else
				{
					isHasMore = true;
				}
				
				if (getDataFlag != 2)
				{
					if (commentList.size() > 0) commentList.clear();
					commentList.addAll(object);
					
				}
				else
				{
					commentList.addAll(object);
				}
				// tvCommentCount.setText("评论(" + commentList.size() + ")");
				adapter.notifyDataSetChanged();
			}
			else
			{
				isHasMore = false;
				if (getDataFlag != 2)
				{
					//					details_lv.setVisibility(View.GONE);
					llayEmpty.setVisibility(View.VISIBLE);
				}
			}
			
		}
		
		/*
		 * (non-Javadoc)
		 * @see com.shwread.http.base.ObjectHttpResponseHandler#getType()
		 */
		@Override
		public Type getType() {
			// TODO Auto-generated method stub
			return new TypeToken<List<CommentBean>>()
			{
			}.getType();
		}
		
	}
	
	class GetCommentTotalNumHandler
	        extends
	        ObjectHttpResponseHandler<NumberInfo>
	{
		
		/*
		 * (non-Javadoc)
		 * @see com.shwread.http.base.ObjectHttpResponseHandler#onFailure(int,
		 * org.apache.http.Header[], java.lang.String, java.lang.Throwable)
		 */
		@Override
		public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
			Logger.e(throwable);
			
		}
		
		/*
		 * (non-Javadoc)
		 * @see com.shwread.http.base.ObjectHttpResponseHandler#onSuccess(int,
		 * org.apache.http.Header[], java.lang.Object, java.lang.String)
		 */
		@Override
		public void onSuccess(int statusCode, Header[] headers, NumberInfo object, String responseString) {
			Logger.i(responseString);
			if (object != null)
			{
				Intent detailIntent = new Intent();
				Bundle bundle = new Bundle();
				bundle.putInt("position", getIntent().getExtras().getInt("position"));
				bundle.putInt("count", object.commentNum);
				detailIntent.putExtra(BUNDLE_DATA, bundle);
				setResult(RESULT_OK, detailIntent);
				if (object.commentNum == 0)
				{
					tvCommentCount.setText("评论");
				}
				else
				{
					tvCommentCount.setText("评论(" + object.commentNum + "" + ")");
					if (object.commentNum > 99) tvCommentCount.setText("评论(99+)");
				}
				//				details_lv.setVisibility(View.VISIBLE);
				//				if(object.commentNum==0)
				llayEmpty.setVisibility(object.commentNum == 0 ? View.VISIBLE : View.GONE);
			}
			else
			{
				tvCommentCount.setText("评论");
				//				details_lv.setVisibility(View.GONE);
				llayEmpty.setVisibility(View.VISIBLE);
				isHasMore = false;
			}
			
		}
		
		/*
		 * (non-Javadoc)
		 * @see com.shwread.http.base.ObjectHttpResponseHandler#getType()
		 */
		@Override
		public Type getType() {
			// TODO Auto-generated method stub
			return new TypeToken<NumberInfo>()
			{
			}.getType();
		}
		
	}
	
	/****************************** list 适配器 **************************/
	class MyAdapter
	        extends
	        BaseAdapter
	{
		
		@Override
		public int getCount() {
			return (commentList == null || commentList.size() == 0 ? 0 : commentList.size());
		}
		
		@Override
		public Object getItem(int arg0) {
			return (commentList == null || commentList.size() == 0 ? "" : commentList.get(arg0));
		}
		
		@Override
		public long getItemId(int arg0) {
			return arg0;
		}
		
		@SuppressWarnings ("unused")
		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			ViewHolder holder = new ViewHolder();
			if (convertView == null)
			{
				
				convertView = LayoutInflater.from(context).inflate(R.layout.new_interaction_details_lv_item, parent, false);
				holder.civCommentHead = (CircleImageView) convertView.findViewById(R.id.new_interaction_details_lv_item_head_civ);
				holder.tvCommentName = (TextView) convertView.findViewById(R.id.new_interaction_details_lv_item_tv_name);
				holder.tvCommentContent = (TextView) convertView.findViewById(R.id.new_interaction_details_lv_item_tv_msg);
				holder.tvCommentTime = (TextView) convertView.findViewById(R.id.new_interaction_details_lv_item_tv_time);
				convertView.setTag(holder);
			}
			else
			{
				holder = (ViewHolder) convertView.getTag();
			}
			
			CommentBean commentBean = (CommentBean) getItem(position);
			if (Utils.isEmpty(commentBean.commentUserHeadImage))
			{
				holder.civCommentHead.setImageResource(R.drawable.new_i_team_set_def_head);
			}
			else
			{
				ImageLoaderUtil.loadWebUrl(commentBean.commentUserHeadImage, holder.civCommentHead);
			}
			holder.tvCommentName.setText(getNickName(commentBean));
			// holder.tvCommentContent.setText(getContent(commentBean));
			if (commentBean != null)
			{
				
				if (Utils.isEmpty(commentBean.replyCommentUserNickName))
				{
					holder.tvCommentContent.setText(commentBean.content);
				}
				else
				{
					String str = "<FONT COLOR='#676767'>" + commentBean.replyCommentUserNickName + "</FONT>";
					
					// holder.tvCommentContent.setText("回复  " +
					// Html.fromHtml(str) + ": " + commentBean.content);
					String content = getResources().getString(R.string.replay_content, commentBean.replyCommentUserNickName, commentBean.content);
					holder.tvCommentContent.setText(Html.fromHtml(content));
				}
			}
			else
			{
				holder.tvCommentContent.setText("");
			}
			
			holder.tvCommentTime.setText(Utils.isEmpty(Long.toString(commentBean.createTime)) ? "" : DateUtil.getRegionTime(commentBean.createTime));
			return convertView;
		}
		
	}
	
	private String getNickName(CommentBean bean) {
		if (null == bean) return "";
		if (Util.isNotEmpty(bean.commentUserNickName)) return bean.commentUserNickName;
		final String account = bean.commentUserAccount;
		if (Util.isEmpty(account)) return "";
		return Util.formatPhone(account);
	}
	
	private String getContent(CommentBean bean) {
		String str = "";
		if (bean != null)
		{
			if (!Util.isEmpty(bean.replyCommentUserNickName))
			{
				str = "<FONT COLOR='#676767'>" + bean.commentUserNickName + "</FONT>";
				return String.format("回复  %s: %s", Html.fromHtml(str), bean.content);
			}
			else
			{
				return bean.content;
			}
		}
		else
		{
			return "";
		}
		// if (null != bean) { return
		// Util.isEmpty(bean.replyCommentUserNickName) ? bean.content :
		// String.format("回复  %s: %s",
		// Html.fromHtml("<p><font color=\"#ff0000\">bean.replyCommentUserNickName</p>"),
		// bean.content); }
		// if (null != bean) { return
		// Util.isEmpty(bean.replyCommentUserNickName) ? bean.content :
		// String.format("回复  %s: %s", str, bean.content); }
	}
	
	class ViewHolder
	{
		private CircleImageView civCommentHead;
		private TextView         tvCommentName;
		private TextView         tvCommentContent;
		private TextView         tvCommentTime;
	}
	
	/****************************** GridView适配器 *****************************************/
	private class GridViewAdapter
	        extends
	        BaseAdapter
	{
		private List<String> imaList = new ArrayList<String>();
		private ImageView    picView = new ImageView(context);
		private HolderView   holder;
		
		public GridViewAdapter(List<String> List) {
			this.imaList = List;
		}
		
		@Override
		public int getCount() {
			// TODO Auto-generated method stub
			return imaList.size();
		}
		
		@Override
		public Object getItem(int position) {
			// TODO Auto-generated method stub
			return imaList.get(position);
		}
		
		@Override
		public long getItemId(int position) {
			// TODO Auto-generated method stub
			return position;
		}
		
		@Override
		public View getView(int position, View view, ViewGroup arg2) {
			
			if (view == null)
			
			{
				
				view = View.inflate(context, R.layout.gridview_item, null);
				holder = new HolderView();
				holder.iv_item = (ImageView) view.findViewById(R.id.iv_gridview_item);
				
				//				ImageLoaderUtil.loadWebUrl(List.get(position), picView);
				//				view = picView;
				view.setTag(holder);
			}
			else
			{
				holder = (HolderView) view.getTag();
			}
			holder.iv_item.setLayoutParams(new LayoutParams((MomentsPage.width / 4 * 3 - 10) / 3, (MomentsPage.width / 4 * 3 - 10) / 3));
			//			holder.iv_item.setLayoutParams(new LayoutParams((MomentsPage.width - 200) / 3, (MomentsPage.width - 200) / 3));
			ImageLoaderUtil.loadWebUrl(imaList.get(position), holder.iv_item);
			return view;
		}
		
		private class HolderView
		{
			ImageView iv_item;
		}
		
	}
}
